/**
 * @param {number[]} A
 * @return {number}
 */
var repeatedNTimes = function(A) {
  let tag = A.length / 2
  var obj = {}
  for (let i = 0; i < A.length; i++) {
    if (obj[A[i]] && obj[A[i]] == tag - 1) {
      return A[i]
    } else if (!obj[A[i]]) {
      obj[A[i]] = 1
    } else {
      obj[A[i]]++
    }
  }
}

console.log(repeatedNTimes([5, 1, 5, 2, 5, 3, 5, 4]))
